﻿#include <iostream>
using namespace std;
int main()
{
	int* p = new int;
	*p = 20;
	cout << *p << endl;
	delete p;
	int* ptr = new int[10];
	for (int i = 0; i < 10; i++)
	{
		*(ptr + i) = i;
	}
	for (int i = 0; i < 10; i++)
	{
		cout << *(ptr + i) << " ";
	}
	delete[]  ptr;
	return 0;
}
////动态申请⼀个int类型的空间
//int* ptr1 = new int;
////动态申请⼀个int类型的空间并初始化为10
//int* ptr2 = new int(10);
////动态申请10个int类型的空间
//int* ptr3 = new int[10];
////释放内存空间
//delete ptr1;
//delete ptr2;
//delete[] ptr3;
//📌⼩提⽰
////#include <iostream>
////using namespace std;
//////全局变量-存放在内存的静态区（数据段）
////int n2 = 10;
////int arr2[5];
////int main()
////{
////	//局部变量-存放在内存的栈区
////	int n1 = 10;
////	int arr1[5];
////	return 0;
////}
//////int n = 10; //向内存申请4个字节的空间
//////char arr1[5]; //向内存申请5个字节的空间
//////int arr2[5];//向内存申请20个字节的空间
////
//////#include <iostream>
//////using namespace std;
//////int main()
//////{
//////	int arr[10] = { 0 };
//////	int* p = &arr[0];
//////	int i = 0;
//////	for (i = 0; i < 10; i++)
//////	{
//////		*(p + i) = i + 1;
//////	}
//////	while (p < &arr[10])
//////	{
//////		cout << *p << " ";
//////		p++;
//////	}
//////	return 0;
//////}
//////#include <iostream>
//////using namespace std;
//////int main()
//////{
//////	int arr[10] = { 0 };
//////	int* p = &arr[0];
//////	int i = 0;
//////	for (i = 0; i < 10; i++)
//////	{
//////		*(p + i) = i + 1;
//////	}
//////	for (i = 0; i < 10; i++)
//////	{
//////		cout << *p << " ";
//////		p++;
//////	}
//////	return 0;
//////}
////////void test(void* p)
////////{
////////	//....
////////}
////////int main()
////////{
////////	int a = 10;
////////	test(&a);
////////	double d = 3.14;
////////	test(&d);
////////	return 0;
////////}
////////#include <cstdio>
////////int main()
////////{
////////	int a = 10;
////////	void* pa = &a;
////////	void* pc = &a;
////////	*pa = 10;
////////	*pc = 0;
////////	return 0;
////////}
//////////#include <cstdio>
//////////int main()
//////////{
//////////	int a = 10;
//////////	int* pa = &a;
//////////	char* pc = &a;
//////////	return 0;
//////////}
////////////#include <cstdio>
////////////int main()
////////////{
////////////	int n = 10;
////////////	char* pc = (char*)&n;
////////////	int* pi = &n;
////////////	printf("&n   = %p\n", &n);
////////////	printf("pc   = %p\n", pc); //字符的地址使⽤cout打印会以为是字符串，所以这⾥使⽤printf来打印
////////////	printf("pc+1 = %p\n", pc + 1);
////////////	printf("pi   = %p\n", pi);
////////////	printf("pi+1 = %p\n", pi + 1);
////////////	return  0;
////////////}
////////////#include <iostream>
////////////using namespace std;
////////////int main()
////////////{
////////////	int n = 0x11223344;
////////////	char* pc = (char*)&n;
////////////	*pc = 0;
////////////	return 0;
////////////}
////////////////
////////////////代码1
//////////////#include <iostream>
//////////////using namespace std;
//////////////int main()
//////////////{
//////////////	int n = 0x11223344;
//////////////	int* pi = &n;
//////////////	*pi = 0;
//////////////	return 0;
//////////////}
//////////////#include <iostream>
//////////////using namespace std;
//////////////int main()
//////////////{
//////////////	int a = 100;
//////////////	int* pa = &a;
//////////////	*pa = 0;
//////////////	cout << a << endl;
//////////////	return 0;
//////////////}